<template>
  <el-dialog :title="title" :visible.sync="visible" width="900px" append-to-body>
    <el-form ref="form" inline :model="form" :rules="rules" label-width="170px">
      <el-form-item label="是否生成电子合同" prop="isYc">
        <el-select
          v-model="form.isYc"
          placeholder="是否生成电子合同"
          clearable
          style="width: 240px"
        >
          <el-option value="1" label="是"></el-option>
          <el-option value="0" label="否"></el-option>
        </el-select>
      </el-form-item>
      <br/>
      <el-form-item label="状态" prop="state">
        <el-select
          v-model="form.state"
          placeholder="状态"
          clearable
          style="width: 240px"
        >
          <el-option value="2" label="同意"></el-option>
          <el-option value="-1" label="不同意"></el-option>
        </el-select>
      </el-form-item>
      <br/>
      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="form.remark"
          placeholder="请输入备注"
          clearable
          style="width: 240px"
        />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>

import {approvalState} from "@/api/salepurchase/contract"
export default {
  name: 'approval',
  data(){
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      visible: false,
      form: {
        id: '',
        state: '',
        isYc: '',
        remark: '',
      },
      rules: {
        state: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ]
      }
    }
  },
  methods: {
    open(id) {
      this.form.id=id
      this.visible = true
      this.title = "合同详情"
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            approvalState(this.form).then(response => {
              this.$modal.msgSuccess("审核成功")
              this.visible = false
              this.$emit('confirm')
            })
          }
        }
      })
    },
    // 取消按钮
    cancel() {
      this.visible = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.$refs.form.resetFields()
    },
  },
}
</script>

<style lang="scss" scoped>

</style>
